package com.techblor.util;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * redis消息工具类
 */
@Component
public class RedisMessageUtil {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    /**
     * 发送对象消息
     *
     * @param channel
     * @param message
     */
    public void sendMessage(String channel, Object message) {
        sendMessage(channel, JSON.toJSONString(message));
    }

    /**
     * 发送字符串消息
     *
     * @param channel
     * @param message
     */
    public void sendMessage(String channel, String message) {
        redisTemplate.convertAndSend(channel, message);
    }
}
